package com.zmj.controller;

import com.zmj.entity.UserInfo;
import com.zmj.service.IUserInfoService;
import com.zmj.service.impl.UserInfoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/toUpdate")
public class ToUpdateServlet extends HttpServlet {
    IUserInfoService userInfoService=new UserInfoServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
     doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String s=req.getParameter("uid");
      if (s==null||"".equals(s.trim())){
          resp.sendRedirect("update.jsp");
      }else {
        long uid=Long.parseLong(s);
       UserInfo userInfo= userInfoService.getInfoByUid(uid);
       req.setAttribute("userInfo",userInfo);
       req.getRequestDispatcher("update.jsp").forward(req,resp);
      }
    }
}
